//
//  RegisterViewController.m
//  Hxcsfw
//
//  Created by qiysoft on 2018/1/29.
//  Copyright © 2018年 企友软mac. All rights reserved.
//

#import "RegisterViewController.h"
#import "ZCSegmentView.h"
#import "FirmViewController.h"
#import "PersonViewController.h"

@interface RegisterViewController ()<UIScrollViewDelegate,ZCSegmentViewDelegate>
{
    UIView *bgView;
}
@property (nonatomic,strong) UIScrollView *homeScrollView;
@property (nonatomic,strong) ZCSegmentView *titScrollView;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"注册";
    
    FirmViewController *FirmVC = [[FirmViewController alloc]init];
    [self addChildViewController:FirmVC];
    
    PersonViewController *PersonVC = [[PersonViewController alloc]init];
    [self addChildViewController:PersonVC];
    
    [self initScrollViewItem];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(DKXYClick) name:@"DKXY" object:nil];//打开协议通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(GBXYClick) name:@"GBXY" object:nil];//关闭协议通知
}

- (void)DKXYClick {
    
    if (XIPHONE) {
        bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, 44+64+30)];
    }else {
        bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, 44+64)];
    }
    bgView.backgroundColor = WRGBAColor(0, 0, 0, 0.2);

    [self.view addSubview:bgView];
}
- (void)GBXYClick {
    
    [bgView removeFromSuperview];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 初始化scrollView上的页面
- (void)initScrollViewItem {
    
    if (XIPHONE) {
        _titScrollView = [[ZCSegmentView alloc]initWithFrame:CGRectMake(0, 94, WSCREENH_WIDTH, 44)];
    } else {
        _titScrollView = [[ZCSegmentView alloc]initWithFrame:CGRectMake(0, 64, WSCREENH_WIDTH, 44)];
    }
    
    _titScrollView.delegate = self;
    _titScrollView.titleArray = @[@"企业用户注册",@"个人用户注册"];
    _titScrollView.titleSpacing = 0;
    _titScrollView.labelFont = [UIFont systemFontOfSize:15];
    _titScrollView.bottomLabelTextColor = [UIColor blackColor];
    _titScrollView.topLabelTextColor = [UIColor colorWithRed:0.22 green:0.6 blue:0.9 alpha:1];//选中字体颜色
    _titScrollView.selectedBackgroundColor = [UIColor whiteColor];
    _titScrollView.selectedBgViewCornerRadius = 20;
    _titScrollView.sliderHeight = 3;
    _titScrollView.sliderColor = [UIColor colorWithRed:0.22 green:0.6 blue:0.9 alpha:1];//下划线颜色
    _titScrollView.sliderTopMargin = 3;
    _titScrollView.duration = 0.3;
    
    UILabel *lineLb = [[UILabel alloc]initWithFrame:CGRectMake(0, 43, WSCREENH_WIDTH, 1)];
    lineLb.backgroundColor = [UIColor colorWithRed:0.87 green:0.87 blue:0.87 alpha:1];
    [_titScrollView addSubview:lineLb];
    [self.view addSubview:_titScrollView];
    
    CGFloat tableViewW = WSCREENH_WIDTH;
    CGFloat tableViewH = self.view.height - CGRectGetMaxY(_titScrollView.frame)+72;
    
    _homeScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_titScrollView.frame), tableViewW, WSCREENH_HEIGHT-44)];
    _homeScrollView.delegate = self;
    _homeScrollView.backgroundColor = [UIColor clearColor];
    _homeScrollView.contentSize = CGSizeMake(tableViewW * 2, tableViewH);
    _homeScrollView.pagingEnabled = YES;
    _homeScrollView.bounces = NO;
    _homeScrollView.scrollEnabled = NO;
    [self.view addSubview:_homeScrollView];
    
    NSArray *color = @[[UIColor purpleColor],[UIColor redColor]];
    for (int i = 0; i < self.childViewControllers.count; i++) {
        UIViewController *vc = self.childViewControllers[i];
        vc.view.frame = CGRectMake(i * tableViewW, 0, tableViewW, WSCREENH_HEIGHT-44);
        vc.view.backgroundColor = color[i];
        [_homeScrollView addSubview:vc.view];
    }
    _titScrollView.outScrollView = _homeScrollView;
    
}

- (void)buttonClick:(NSInteger)index {
    [_homeScrollView setContentOffset:CGPointMake(self.view.width * index, 0) animated:NO];
}

-(void)dealloc{
    //移除所有通知监控
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"RegisterBack" object:nil];
}

@end
